<?php
    @include_once("./conn.php");

    $id = $_POST["id"];
    $num = $_POST["num"];
    

    if(!($id)){
        argErr();
    }


   
    $search = "select * from `shoppingcar` where id = '$id'";
    $result = mysqli_query($conn,$search);

    $item = mysqli_fetch_assoc($result);  // 查询的结果

    
    if($num>1){
        if($item){   
            $sql = "update `shoppingcar` set buyNum = buyNum - 1 where id = '$id'";
        }
    }
    
    mysqli_query($conn,$sql);   
    $rows = mysqli_affected_rows($conn);

    $obj = array();
    if($rows>0){
        $obj["status"] = true;
        $obj["detail"] = "商品数量-1";
    }else{
        $obj["status"] = false;
        $obj["detail"] = "商品数量减少失败";
        $obj["sql"] = $sql;
    }
    echo json_encode($obj);
?>